package com.cat.dataStructure02;

/**
 *   @description https://leetcode.cn/problems/array-nesting/
 *   @author 曲大人的喵
 *   @create 2025/10/6 21:26
 *   @since JDK17
 */

public class Solution05 {
    public int arrayNesting(int[] nums) {
        int n = nums.length, ans = 0;
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int cur = i; nums[cur] != -1; cnt++) {
                int t = nums[cur];
                nums[cur] = -1;
                cur = t;
            }
            ans = Math.max(ans, cnt);
        }

        return ans;
    }
}
